namespace SimpleWebServices.Web.Mvc
{
    using System;
    using System.Web;
    using Moq;
    using SimpleWebServices;
    using SimpleWebServices.Data;
    using SimpleWebServices.Web;
    using Xunit;

    public sealed class ImplicitUriConverterFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<ImplicitUriConverter<TestRecord>>()
                .DerivesFrom<UriConverter>()
                .IsConcreteClass()
                .IsSealed()
                .NoDefaultConstructor()
                .Implements<IConvertUri>()
                .Result);
        }

        [Fact]
        public void ctor_Type()
        {
            Assert.NotNull(new ImplicitUriConverter<TestRecord>(typeof(ResourceControllerOfIResourceDummy)));
        }

        [Fact]
        public void ctor_TypeNull()
        {
            Assert.Throws<ArgumentNullException>(() => new ImplicitUriConverter<TestRecord>(null as Type));
        }

        [Fact]
        public void prop_Urn_get()
        {
            try
            {
                var mock = new Mock<HttpContextBase>();
                mock.SetupGet<string>(x => x.Request.Path).Returns("/foo/bar").Verifiable();
                HttpContextFactory.Mock = mock.Object;

                AbsoluteUri expected = "urn://example.com/foo/bar";
                AbsoluteUri actual = new ImplicitUriConverter<TestRecord>(typeof(ResourceControllerOfIResourceDummy)).Urn;

                Assert.Equal<AbsoluteUri>(expected, actual);

                mock.VerifyAll();
            }
            finally
            {
                HttpContextFactory.Reset();
            }
        }
    }
}